package cn.jsp;

import java.io.*;

import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;
import cn.jsp.dao.*;
@WebServlet(name = "helloServlet", value = "/hello-servlet")
public class HelloServlet extends HttpServlet {
  private String message;

  public void init() {
    message = "Hello World!";
  }

  public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");

    request.getSession().setAttribute("user","hello");
    ApplicationContext ctx= WebApplicationContextUtils.getRequiredWebApplicationContext(request.getServletContext());
    StuDao dao=ctx.getBean(StuDao.class);
    response.getWriter().println(dao.query());
  }

  public void destroy() {
  }
}